<template>
    <div class="components-container">
        <div class="header-form">
            <div class="layui-inline">
                <label class="layui-form-label">接尸日期</label>
                <div class="layui-inline">
                    <el-radio-group v-model="selectDataEixend.regDateValue" @change="getData">
                        <el-radio-button :label="DateSelectMode.now" class="radio">当日</el-radio-button>
                        <el-radio-button :label="DateSelectMode.tomorrow" class="radio">明日</el-radio-button>
                        <el-radio-button :label="DateSelectMode.future" class="radio">以后</el-radio-button>
                        <el-radio-button :label="DateSelectMode.all" class="radio">全部</el-radio-button>
                    </el-radio-group>
                </div>
            </div>
            <!-- <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-inline">
                    <el-radio-group v-model="selectData.StatusEquals" @change="getData">
                        <el-radio-button label="A" class="radio">预约中</el-radio-button>
                        <el-radio-button label="B" class="radio">已处理</el-radio-button>
                        <el-radio-button label="C" class="radio">已取消</el-radio-button>
                    </el-radio-group>
                </div>
            </div> -->
            <div class="layui-inline">
                <label class="layui-form-label">逝者姓名</label>
                <div class="layui-inline">
                    <el-input  v-model="selectData.RegnameLike" @keydown.enter.native="btnSearch" placeholder="请输入逝者姓名"></el-input>
                </div>
            </div>
            <div class="layui-inline" v-if="IsSubscribeUseNum">
                <label class="layui-form-label">业务编号</label>
                <div class="layui-inline">
                    <el-input  v-model="selectData.RegbussnumEquals" placeholder="请输入业务编号" @keydown.enter.native="btnSearch"></el-input>
                </div>
            </div>
            <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
            <el-button type="warning"  @click="btnRepeats" >重置</el-button>
        </div>
        <div>
            <ul class="toolList">
                <li>
                    <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button>
                </li>
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                    <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>
        <el-dialog :title="soundtitle" :visible.sync="dialogTableVisible" :modal-append-to-body="false" width="60%">
            <!-- <el-date-picker v-model="value1" type="date" placeholder="选择日期"></el-date-picker> -->
            <div class="layui-inline" v-if="soundtitle == '录音绑定'">
                <label class="layui-form-label">录音日期</label>
                <el-date-picker v-date v-model="sounddata" type="date" placeholder="选择日期"></el-date-picker>
                <el-button type="primary" @click="btnSearchs" :loading="loadings">搜索</el-button>
                <el-button @click="btnRepeat">重置</el-button>
            </div>
            <el-table ref="multipleTable" :data="diechdData" tooltip-effect="dark" style="width: 100%" max-height="450" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column prop="SDGTALKDATEDESC" label="通话日期" width="120"></el-table-column>
                <el-table-column prop="SDGTALKTIMEDESC" label="通话时间" width="120"></el-table-column>
                <el-table-column prop="SDGREMOTECODE" label="对方电话" width="180"></el-table-column>
                <el-table-column prop="read" label="播放录音">
                    <template slot-scope="scope">
                        <audio :src="scope.row.SDGTALKURL" controls="controls">播放</audio>
                    </template>
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="toggleSelection()">取 消</el-button>
                <el-button v-if="soundtitle == '录音绑定'" type="primary" @click="binding()">绑 定</el-button>
            </span>
        </el-dialog>
        <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" :infos="infos" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        <!-- 老版本（萧山、海曙、奉化、开化） -->
        <mainmodel v-if="!AppointmentView" ref="models" @refreshData="getData"></mainmodel>
        <!-- 嵊州 -->
        <mainmodelSen v-if="AppointmentView" ref="models" @refreshData="getData"></mainmodelSen>
        <!-- 之后的新版本 -->
        <newmainmodel ref="newmodels" @refreshData="getData"></newmainmodel>
        <printmodal ref="printPdf"></printmodal>
        <OperationHistory ref="OperationHistory"></OperationHistory>
        <!-- 宁波派车信息 -->
        <carinformation ref="carinformation" @refresh="getData"></carinformation>
        <!-- 派车登记 -->
         <carSendNewMain ref="carSendNewMain"></carSendNewMain>
        <!-- 导入预约数据 -->
        <input type="file" name="file" id="file" ref="file" @change="importExcel" style="display:none;">
    </div>
</template>

<script>
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { DATESELECTMODE } from "@/const/const.js";
import mainmodel from "@/views/business/phoneAppointmentMain";
import mainmodelSen from "@/views/business/phoneAppointmentMainSen";
import newmainmodel from "./phoneAppointmentMainNew";
import carinformation from "@/views/business/carinformation"; //宁波 弹框派车信息一览表
import printmodal from "@/components/Pdf/Print";
import { PRINT } from "@/components/Pdf/PDF.js";
import { PRPORDER } from "@/const/orderConst.js";
import { ORDER } from "@/const/orderConst.js";
import OperationHistory from "@/views/jointPlatform/OperationHistory";
import carSendNewMain from "@/views/server/carSendNewMain";
require('script-loader!xlsx-style/dist/xlsx.full.min');

export default {
  name: "phoneAppointment",
  mixins: [manage],
  data() {
    return {
      dataListc: [],  //导出的接收数据
      DateSelectMode: DATESELECTMODE,
      double: null,
      //编码
      carLics: [],
      drivers: [],
      preSitDesc: null,
      infos: null,
      issendcar: null,
      dialogTableVisible: false,
      reserveType: [],
      reserveStatus: [],
      serviceListType: [],
      sexType: [],
      ServiceItemsList: [],
      checkedItem: [],
      diechdData: [],
      multipleSelection: [],
      soundtitle: null,
      sounddata: null,
      loadings: false,
      downloadLoading: false,
      selectData: {
        RegnameLike: null,
        RegbussnumEquals: null,
        StatusEquals: null,
        REGCORPSEDATEEquals: null
      },
      selectDataEixend: {
        regDateValue: null
      },
      prpData: {
        PRPID: null,
        PRPNO: null,
        PRPLINKMAN: null,
        PRPLINKPHONE: null,
        PRPORIGINALCALL: null,
        PRPCALLDATE: null,
        PRPDEADNAME: null,
        PRPYITIQX: null,
        PRPDESCRIBE: "",
        PRPCORPSEADDRESS: null,
        PRPWORKDATE: null,
        //服务项目预约信息
        Psts: [],
        //派车信息
        Cdh: {
          CDHCARID: null,
          CARLIC: null,
          CARCODNAME: null,
          CARCODNAMEDESC: null,
          CDHDRIVER: null,
          STANAME: null
        },
        chl: {
          SDGTALKDATE: "", //通话日期
          SDGTALKID: "", //通话记录ID
          SDGTALKURL: "" //文件地址
        }
      },
      cdhcar: ["", ""],
      carType: null,
      ischangered: null,
      ischangnb: null,
      IsSubscribeUseNum: null,
      AppointmentView: null,
    };
  },
  methods: {
    //获取电话预约数据
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.QueryReserve,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
          this.dataList.forEach(data => {
            data.PRPWORKDATE = data.PRPWORKDATE.substring(0, 16);
            data.PRPCREMATIONDATEDESC = data.PRPCREMATIONDATEDESC.substring(0, 16);
          });
          this.$nextTick(function() {
            let rows = document.getElementsByClassName("el-table__row");
            if (this.ischangered) {
              this.dataList.forEach((item, index) => {
                rows[index].style.color = "#606266";
                if (item.PRPCREMATION === "A") {
                  rows[index].style.color = "red";
                }
              });
            }
            if (this.ischangnb) {
              this.dataList.forEach((item, index) => {
                rows[index].style.color = "#606266";
                if (item.PRPCREMATION === 'A'||item.PRPCREMATION === 'C') {
                  rows[index].style.color = "#007eff";
                }
                 if(item.PRPCREMATION === 'D'){
                    rows[index].style.color = 'red';
                  }
              });
            }
          });
        }
      );
    },
    toggleSelection(rows) {
      // this.$refs.multipleTable.clearSelection();取消选中
      this.dialogTableVisible = false;
      // this.diechdData = [];
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //绑定录音
    binding() {
      let data = {
        PRPID: this.currentRow.PRPID,
        list_Sdg: this.multipleSelection
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().SoundRecord.Speechmatching,
        res => {
          if (res.data.msg == "成功") {
            this.dialogTableVisible = false;
          } else {
            alert(res.data.msg);
          }
        }
      );
    },
    //获取表头
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetPhoneReserveColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //导出excel表
    exportExcel() {
      let data = {
        PageIndex: -1,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.QueryReserve,
        res => {
          this.dataListc = res.data.content.OutData;
          this.dataListc.forEach(data => {
            data.PRPWORKDATE = data.PRPWORKDATE.substring(0, 16);
          });
          if (this.dataListc.length === 0) {
            this.$message.error("无导出数据！");
            return;
          }
          this.downloadLoading = true;
          require.ensure([], () => {
            const { export_json_to_excel } = require("@/vendor/Export2Excel");
            export_json_to_excel(this.headList, this.dataListc, "电话预约");
            this.downloadLoading = false;
          });
        }
      );
    },
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case "导出":
          this.exportExcel();
          break;
        case PRPORDER.ADD:
          this.$refs.models.open(this.order, false);
          // this.$refs.newmodels.open(this.order, false);
          break;
        case "义乌新增":
          this.$refs.newmodels.open(this.order, false);
          break;
        //宁波 个性化（派车信息一览表）
        case "派车信息":
          this.$refs.carinformation.open(this.order, false);
          break;
        case PRPORDER.MODIFY:
          this.$refs.models.open(this.order, this.currentRow.PRPID);
          break;
        case "义乌修改":
          this.$refs.newmodels.open(this.order,this.currentRow.PRPID,this.currentRow.PRPSTATUS,this.currentRow.REGPRPID);
          break;
        case PRPORDER.DELETE:
          this.confirm(callback => {
            this.dataDelete();
          },'此操作将永久删除该数据,同时删除派车历史, 是否继续?');
          break;
        case PRPORDER.INFO:
          this.$refs.models.open(this.order, this.currentRow.PRPID);
          break;
        case "义乌详情":
          this.$refs.newmodels.open(this.order,this.currentRow.PRPID,this.currentRow.PRPSTATUS,this.currentRow.REGPRPID);
          break;
        case PRINT.PRINTSENDYW: //打印派车单
          this.$refs.printPdf.open(this.order, this.currentRow.PRPID,this.currentRow.PRPSTATUS,this.currentRow.REGPRPID);
          break;
        case PRINT.PHONERECORDER:
          this.$refs.printPdf.open(this.order);
          break;
        case PRINT.PDFDEADLABEL:
          this.$refs.printPdf.open(this.order, this.currentRow.PRPID);
          break;
        case PRINT.PDFFLOWSHEET:
          this.$refs.printPdf.open(this.order, this.currentRow.PRPID);
          break;
        case "操作历史":
          this.$refs.OperationHistory.open("操作历史", this.currentRow.PRPID);
          break;
        case "录音匹配":
          this.soundtitle = "录音绑定";
          this.diechdData = [];
          this.dialogTableVisible = true;
          this.getRecordifm();
          break;
        case "录音详情":
          this.soundtitle = "录音详情";
          this.diechdData = [];
          this.dialogTableVisible = true;
          this.detailSound();
          break;
        case "导入预约数据":
          document.getElementById('file').click()
          break;
        case "取消预约":
          this.cancleOrder(this.currentRow.PRPID)
          break;
        case "恢复预约":
          this.restoreOrder(this.currentRow.PRPID)
          break;
        case "派车登记":
        this.$refs.carSendNewMain.open('义乌派车', this.currentRow.PRPNO);
        break;  
        default:
      }
    },

    //数据重置
    dataRepeat() {
      this.pcrFirst = false;
      this.preFirst = false;
      this.checkedItem = [];
      this.cdhcar = ["", ""];
      Object.assign(this.$data.prpData, this.$options.data().prpData);
    },
    // 取消预约
    cancleOrder(id){
      this.$confirm("此操作将取消此预约, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
      .then(() => {
        let Data = {
          PRPID: id
        };
        apiBase.DoService(
          Data,
          apiBase.getApiAdress().Reserve.ModifyCancelReserve,
          res => {
            this.getData();
            this.$message({
              type: "success",
              message: "已取消此预约"
            });
          }
        );
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "已取消此操作"
        });
      });
    },
    restoreOrder(id){
      this.$confirm("此操作将恢复此预约, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
      .then(() => {
        let Data = {
          PRPID: id
        };
        apiBase.DoService(
          Data,
          apiBase.getApiAdress().Reserve.ModifyReserve,
          res => {
            this.getData();
            this.$message({
              type: "success",
              message: "已恢复此预约"
            });
          }
        );
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "已取消此操作"
        });
      });
    },
    //登记删除
    dataDelete() {
      let Data = {
        PRPID: this.currentRow.PRPID
      };
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().Reserve.DeletePhoneReserve,
        res => {
          this.getData();
        }
      );
    },
    //获取录音信息
    getRecordifm() {
      var dates = new Date();
      var strtime = formatDate(new Date(dates.setDate(1)), "yyyyMMdd");
      var endtime = formatDate(new Date(), "yyyyMMdd");
      // var strtime = 20180701;
      // var endtime = 20180731;
      let data = {
        sdStartDate: strtime,
        sdEndDate: endtime,
        SDGPRPID: this.currentRow.PRPID
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().SoundRecord.QuerySoundRecord,
        res => {
          this.diechdData = res.data.content;
          // for(let index in this.diechdData){
          //     this.diechdData[index].SDGTALKDATEDESC = this.diechdData[index].SDGTALKDATEDESC;
          //     this.diechdData[index].SDGTALKTIMEDESC = this.diechdData[index].SDGTALKTIMEDESC;
          //     this.diechdData[index].SDGREMOTECODE = this.diechdData[index].SDGREMOTECODE;
          //   }
          setTimeout(() => {
            for (var i = 0; i < this.diechdData.length; i++) {
              if (this.diechdData[i].SDGID != null) {
                this.$refs.multipleTable.toggleRowSelection(
                  this.diechdData[i],
                  true
                );
              }
            }
          }, 0);
        }
      );
    },
    //获取录音详情
    detailSound() {
      let data = {
        SDGPRPID: this.currentRow.PRPID
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().SoundRecord.DetailSoundRecord,
        res => {
          this.diechdData = res.data.content.list_SDG;
          for (let index in this.diechdData) {
            this.diechdData[index].SDGTALKDATEDESC = this.diechdData[
              index
            ].SDGTALKDATEDESC;
            this.diechdData[index].SDGTALKTIMEDESC = this.diechdData[
              index
            ].SDGTALKTIMEDESC;
            this.diechdData[index].SDGREMOTECODE = this.diechdData[
              index
            ].SDGREMOTECODE;
            // this.diechdData[index].read = '播放';
          }
        }
      );
    },
    //搜索录音
    btnSearchs() {
      this.loadings = true;
      if (this.sounddata == null) {
        this.loadings = false;
      }
      let data = {
        sdStartDate: formatDate(this.sounddata, "yyyyMMdd"),
        sdEndDate: formatDate(this.sounddata, "yyyyMMdd"),
        SDGPRPID: this.currentRow.PRPID
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().SoundRecord.QuerySoundRecord,
        res => {
          this.loadings = false;
          this.diechdData = res.data.content;
          setTimeout(() => {
            for (var i = 0; i < this.diechdData.length; i++) {
              if (this.diechdData[i].SDGID != null) {
                this.$refs.multipleTable.toggleRowSelection(
                  this.diechdData[i],
                  true
                );
              }
            }
          }, 0);
        }
      );
    },
    //重置
    btnRepeat() {
      this.sounddata = null;
      this.getRecordifm();
    },
    btnRepeats() {
      this.selectDataEixend.regDateValue = DATESELECTMODE.now;
      this.selectData.REGCORPSEDATEEquals = formatDate(new Date(), "yyyyMMdd");
      this.selectData.RegbussnumEquals = null;
      this.selectData.RegnameLike = null;
      this.selectData.StatusEquals = null;
      this.getData();
    },
    //获取预约类型
    getReserveType() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetReserveType,
        res => {
          this.reserveType = res.data.content;
        }
      );
    },
    //获取预约状态
    getReserveStatus() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.GetReserveStatus,
        res => {
          this.reserveStatus = res.data.content;
        }
      );
    },
    //获取遗体去向
    getServiceTypes() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Code.GetYitiqx, res => {
        this.serviceListType = res.data.content;
      });
    },
    //获取性别
    getSexType() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Code.GetSex, res => {
        this.sexType = res.data.content;
      });
    },
    //获取服务项目
    getServiceItems() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.QueryServiceItem,
        res => {
          let serviceList = res.data.content;
          for (var i in serviceList) {
            this.ServiceItemsList.push.apply(
              this.ServiceItemsList,
              serviceList[i].Sits
            );
          }
        }
      );
    },
    //获取车辆信息
    getCar() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Car.QueryCarByType,
        res => {
          let cardata = res.data.content;
          var car = {
            CodeName: "自送",
            CodeValue: "",
            list_Cars: [
              {
                CARLIC: "自送",
                CARID: ""
              }
            ]
          };
          cardata.splice(0, 0, car);

          let legendsCarData = cardata.map(item => ({
            label: item.CodeName,
            value: item.CodeValue,
            children: item.list_Cars.map(caritem => ({
              label: caritem.CARLIC,
              value: caritem.CARID
            }))
          }));

          this.carLics = legendsCarData;
        }
      );
    },
    //获取司机
    getDrivers() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Staff.QueryDriver, res => {
        let driverData = res.data.content,
          legendsDrivers = driverData.map(item => ({
            label: item.STANAME,
            value: item.STAID
          }));
        this.drivers = legendsDrivers;
      });
    },

    //服务项目选择
    ServiceItemsChange(serItems) {
      let pstsList = [];
      for (var i in serItems) {
        var pst = {
          PSTSITID: serItems[i],
          PSTNUMBER: 1
        };
        this.preSitDesc += pstsList.push(pst);
      }
      this.prpData.Psts = pstsList;
    },
    //服务项目选择
    changItem(el, val) {
      var staname = val.SITNAME + "。";
      if (el.target.checked) this.prpData.PRPDESCRIBE += staname;
      else
        this.prpData.PRPDESCRIBE = this.prpData.PRPDESCRIBE.replace(
          staname,
          ""
        );
    },
    issendcars() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Param.GetPrpIsSendCar,
        res => {
          this.issendcar = res.data.content; //是否显示保存按钮
        }
      );
    },
    GetIdvDetail() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Param.GetIdvDetail,
        res => {
          this.issendcar = res.data.content; //是否显示保存按钮
          if (this.issendcar === "10") {
            this.infos = "详情";
          } else if (this.issendcar === "20") {
            this.infos = "义乌详情";
          }
        }
      );
    },
    // excel导入
    importExcel(){
      let that = this
      let inputDOM = this.$refs.file;
      let file = (inputDOM.files);
      let suffix = file[0].name.split(".")[1]
      if (suffix != 'xls' && suffix != 'xlsx') {
          alert('导入的文件格式不正确!')
          return
      };
      const IMPORTFILE_MAXSIZE = 1 * 2048; //这里可以自定义控制导入文件大小
      if (file[0].size / 1024 > IMPORTFILE_MAXSIZE) {
          alert('导入的表格文件不能大于2M')
          return
      };
      let reader = new FileReader();
      let wb;
      let aa = [];
      let text = [];
      reader.onload = function (e) {
          var data = e.target.result;
          wb = XLSX.read(data, {
              type: 'binary'
          });
          let obj = wb;
          aa = JSON.stringify(XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]));
          var u = eval('(' + aa + ')');
          //获取表格中为address的那列存入text中
          u.forEach((item) => {
              for(let i in item){
                  if(i == "逝者姓名"){
                      item['PRPDEADNAME'] = item[i];
                  }else if(i == '逝者身份证号'){
                      item['PRPCARDNO'] = item[i];
                  }else if(i == '逝者性别'){
                      item['PRPDEADSEX'] = item[i];
                  }else if(i == '逝者年龄'){
                      item['PRPDEADAGE'] = item[i];
                  }else if(i == '经办人'){
                      item['PRPLINKMAN'] = item[i];
                  }else if(i == '经办人手机号'){
                      item['PRPLINKPHONE'] = item[i];
                  }else if(i == '其他丧属手机号'){
                      item['PRPSPARELINKPHONE'] = item[i];
                  }else if(i == '经办人与逝者关系'){
                      item['PRPRELATION'] = item[i];
                  }else if(i == '家庭地址(治丧地)'){
                      item['PRPADDID'] = item[i];
                  }else if(i == '详细地址'){
                      item['PRPDETAILADDRESS'] = item[i];
                  }else if(i == '预约日期'){
                      item['PRPWORKDATE'] = item[i].replace(/\//g, '');
                      item['PRPWORKDATE'] = item[i].replace(/-/g, '');
                  }else if(i == '预约时段'){
                      item['PRPWORKTIME'] = item[i].replace(/:/g, '');
                      if(item['PRPWORKTIME'].length>=0 && item['PRPWORKTIME'].length<=6){
                        item['PRPWORKTIME'] = item['PRPWORKTIME'].padEnd(6,'0')
                      }
                  }else if(i == '备注'){
                      item['PRPDESCRIBE'] =  item[i]
                  }else if(i == '预约序号'){
                      item['PRPDAYNUM'] = item[i]
                  }
                  
                  delete item[i];
              }
          });
          u.forEach((item) => {
              for(let i in item){
                  if(!('PRPDEADNAME' in item)){
                      item['PRPDEADNAME'] = "";
                  };
                  if(!('PRPCARDNO' in item)){
                      item['PRPCARDNO'] = "";
                  };
                  if(!('PRPDEADSEX' in item)){
                      item['PRPDEADSEX'] = "";
                  };
                  if(!('PRPDEADAGE' in item)){
                      item['PRPDEADAGE'] = "";
                  };
                  if(!('PRPLINKMAN' in item)){
                      item['PRPLINKMAN'] = "";
                  };
                  if(!('PRPSPARELINKPHONE' in item)){
                      item['PRPSPARELINKPHONE'] = "";
                  };
                  if(!('PRPRELATION' in item)){
                      item['PRPRELATION'] = "";
                  };
                  if(!('PRPADDID' in item)){
                      item['PRPADDID'] = "";
                  };
                  if(!('PRPDETAILADDRESS' in item)){
                      item['PRPDETAILADDRESS'] = "";
                  };
                  if(!('PRPWORKDATE' in item)){
                      item['PRPWORKDATE'] = "";
                  };
                  if(!('PRPWORKTIME' in item)){
                      item['PRPWORKTIME'] = "";
                  };
                  if(!('PRPDESCRIBE' in item)){
                      item['PRPDESCRIBE'] = "";
                  };
                  if(!('PRPDAYNUM' in item)){
                      item['PRPDAYNUM'] = "";
                  };
              }
          });
          apiBase.DoService(
            u,
            apiBase.getApiAdress().Reserve.ImportReserve,
            res => {
              that.$message({
                type: "success",
                message: "导入预约成功!"
              });
              that.getData();
            }
          );
      };
      reader.readAsBinaryString(file[0]);
      this.$refs.file.value = "";
    },
    //模板下载
    exportExcel() {
        this.headList = [{
            "ColumnKey": "q",
            "ColumnName": "省",
            "ColumnOrder": "q",
            "ColumnAlign": "center",
            "ColumnWidth": 90
        }, {
            "ColumnKey": "w",
            "ColumnName": "市",
            "ColumnOrder": "w",
            "ColumnAlign": "center",
            "ColumnWidth": 150
        }, {
            "ColumnKey": "e",
            "ColumnName": "区县",
            "ColumnOrder": "e",
            "ColumnAlign": "center",
            "ColumnWidth": 120
        }, {
            "ColumnKey": "y",
            "ColumnName": "乡镇街道",
            "ColumnOrder": "y",
            "ColumnAlign": "center",
            "ColumnWidth": 350
        }, {
            "ColumnKey": "u",
            "ColumnName": "村、社区",
            "ColumnOrder": "u",
            "ColumnAlign": "center",
            "ColumnWidth": 120
        }, {
            "ColumnKey": "i",
            "ColumnName": "自然村",
            "ColumnOrder": "i",
            "ColumnAlign": "center",
            "ColumnWidth": 120
        },{
            "ColumnKey": "m",
            "ColumnName": "公里数",
            "ColumnOrder": "i",
            "ColumnAlign": "center",
            "ColumnWidth": 120
        }];
        this.datalist = [];
        this.$notify({
          title: '注意：模板样式不可修改！！！',
          type: 'warning',
          position: 'bottom-left',
          offset: 100
        });
        require.ensure([], () => {
          const { export_json_to_excel } = require("@/vendor/Export2Excel");
          // return;
          export_json_to_excel(this.headList, this.datalist, '接运地点模板', undefined, 'jyddmb');
        }).catch(err => {
          // console.log(1545);
        });
    },

    initSeachdata() {
      this.selectDataEixend.regDateValue = DATESELECTMODE.now;
      this.selectData.REGCORPSEDATEEquals = formatDate(new Date(), "yyyyMMdd");
    },
    btnShow(btn) {
      switch (btn) {
        case "义乌新增":
          return true;
          break;
        case "导入预约数据":
          return true;
          break;
        case "派车信息":
          return true;
          break;
        case "派车登记":
          return true;
          break;
        case "新增":
          return true;
          break;
        case "导出":
          return true;
          break;
        case "义乌修改":
          if (this.currentRow){
            if (this.currentRow.PRPSTATUS == 'A'){
              return true;
            }else{
              return false;
            }
          }
          break;
        case "修改":
          if (this.currentRow) return true;
          break;
        case "删除":
          if (this.currentRow){
            if (this.currentRow.PRPSTATUS == 'A'){
              return true;
            }else{
              return false;
            }
          }
          break;
        case "义乌详情":
          if (this.currentRow) return true;
          break;
        case "详情":
          if (this.currentRow) return true;
          break;
        case "义乌打印派车单":
          if (this.currentRow) return true;
          break;
        case "操作历史":
          if (this.currentRow) return true;
          break;
        case "取消预约":
          // PRPSTATUS：A 预约中 B 已处理  C 取消
          if(this.currentRow){
            if (this.currentRow.PRPSTATUS == 'A'){
              return true;
            }
          }
          break;
        case "恢复预约":
          // PRPSTATUS：A 预约中 B 已处理  C 取消
          if(this.currentRow){
            if (this.currentRow.PRPSTATUS == 'A' || this.currentRow.PRPSTATUS == 'B'){
              return false;
            }else{
              return true;
            }
          }
          break;
        default:
          break;
      }
    }
  },

  components: {
    //  sweetModal,
    dataTable,
    mainmodel,
    mainmodelSen, // 嵊州弹框
    printmodal,
    newmainmodel,
    OperationHistory,
    carinformation, //宁波派车信息
    carSendNewMain,
  },
  mounted() {
    this.initSeachdata();
  },
  activated() {
    this.getData();
  },
  created() {
    let data = {};
    apiBase.DoService(
      data,
      apiBase.getApiAdress().Param.GetIsDataTableReddening,
      res => {
        this.ischangered = res.data.content;
      }
    );
    apiBase.DoService(
      data,
      apiBase.getApiAdress().Param.GetIsCreChangeRed,
      res => {
        this.ischangnb = res.data.content;
      }
    );
    apiBase.DoService(
      data,
      apiBase.getApiAdress().Param.GetIsSubscribeUseNum,
      res => {
        this.IsSubscribeUseNum = res.data.content;
      }
    );
    // 个性化弹窗页面(嵊州)
    apiBase.DoService(
      data,
      apiBase.getApiAdress().Param.GetAppointmentView,
      res => {
        this.AppointmentView = res.data.content;
      }
    );
    //this.getData();
    this.getColumns();
    this.getReserveType();
    this.getReserveStatus();
    this.getServiceTypes();
    this.getServiceItems();
    this.getSexType();
    this.getCar();
    this.getDrivers();
    this.issendcars();
    this.GetIdvDetail();
  },
  watch: {
    "selectDataEixend.regDateValue": function(val) {
      this.selectData.REGCORPSEDATEGreater = null;
      this.selectData.REGCORPSEDATEEquals = null;
      switch (val) {
        case DATESELECTMODE.now:
          this.selectData.REGCORPSEDATEEquals = formatDate(new Date(), "yyyyMMdd");
          break;
        case DATESELECTMODE.tomorrow:
          var day = new Date();
          day.setDate(day.getDate() + 1);
          this.selectData.REGCORPSEDATEEquals = formatDate(day, "yyyyMMdd");
          break;
        case DATESELECTMODE.future:
          this.selectData.REGCORPSEDATEGreater = formatDate(new Date(), "yyyyMMdd");
          break;
        default:
          break;
      }
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.sw-table {
  width: 600px;
}
.sw-table-lable {
  width: 100px;
}
.sw-table-input {
  width: 200px;
}
.sweet-content-content {
  width: 100%;
}
</style>